package com.easy.work.function.me.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.easy.work.R;

import java.util.List;

/**
 * @author zhangfeng
 * @date 2017/12/26
 * @desc 我的工作搜索过滤适配器
 */

public class WorkCheckConditionAdapter extends ArrayAdapter<String> {

    private List<String> mList;
    private LayoutInflater mInflater;

    public int getSelect() {
        return select;
    }

    private int select = 0;

    public WorkCheckConditionAdapter(Context context, int resource, List<String> objects) {
        super(context, resource, objects);
        mList = objects;
        mInflater = LayoutInflater.from(context);
    }

    public void refresh(List<String> list) {
        mList.clear();
        mList.addAll(list);
        notifyDataSetChanged();
    }


    @NonNull
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_work_condition_select, parent, false);
            holder = new ViewHolder();
            holder.tvOption = (TextView) convertView.findViewById(R.id.tv_option);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvOption.setText(mList.get(position));
        if (select == position) {
            holder.tvOption.setSelected(true);
        } else {
            holder.tvOption.setSelected(false);
        }
        return convertView;
    }

    public void updateSelect(int pos) {
        select = pos;
        notifyDataSetChanged();
    }

    class ViewHolder {
        TextView tvOption;
    }

}
